/*******************************************************************************

PooledRegions analysis_sumstats.do

2018.08.29 (DJ) Created

This do file performs village-level sum statistics based on RQ and Transport Surveys. 

*******************************************************************************/


/*******************************************************************************
	Village-Level Sum Stats
*******************************************************************************/

use "${analysis}/Kilimanjaro rq_census_mt_vt_google.dta", clear
rename  (district ward village_name market) (survey_district survey_ward survey_village primary_market)

append using "${analysis}/Manyara rq_census_mt_vt_google.dta"

// these are market-level variables, so only keep the unique values. 
	egen marketunique = tag(primary_market survey_region)
	foreach var of varlist google_mkt*{
		replace `var' = . if marketunique==0
	}	
	
#d;
	local sum_stat_varlist "
	
	census_bothsex
	
	google_vil_mkt_km
	google_vil_mkt_min_rt
	
	VT_vil_mkt_min_rt
	VT_vil_mkt_cost_USD_rt
	
	google_vil_nearcity_km
	google_vil_nearcity_min_rt
	
	VT_vil_nearcity_cost_USD_rt
	
	RQ_percent_paved 
	RQ_percent_gravel 
	RQ_percent_dirt 
	
	RQ_rural_cost_USD_rt 
	RQ_rural_speed 
	
	google_vil_mkt_speed
	google_mkt_nearcity_speed
	
	"
	;
#d cr

estimates clear
bys survey_region: fsum `sum_stat_varlist'

eststo: estpost sum `sum_stat_varlist', d

esttab using "${pool_results}/PooledRegions sumstats.csv", replace ///
	cell("mean(fmt(a2)) p50(fmt(2)) sd(fmt(a2)) count") noobs

exit
